package main.java.com.amanda.utils;

import edu.princeton.cs.algs4.StdOut;
import main.java.com.amanda.suafa.BinarySearchST;
import java.util.Scanner;

/**
 * @author amanda
 * @Description 符号表的用例， 评估查找算法的性能
 */

public class FrequencyCounter {
    public static void main(String[] args) {

        // 最小键长
        int minlen = new Scanner(System.in).nextInt();
        BinarySearchST<String, Integer> st = new BinarySearchST<>();
        String[] str = {"it","was","the","best","of","times",
                "it","was","the","worst","of","time",
                "it","was","the","age","of","wisdom",
                "it","was","the","age","of","foolishness",
                "it","was","the","epoch","of","belief",
                "it","was","the","epoch","of","incredulity",
                "it","was","the","season","of","light",
                "it","was","the","season","of","darkness",
                "it","was","the","spring","of","the","hope",
                "it","was","the","winter","o","despair"
        };
        int n = str.length;
        for (int i = 0; i < n; i++) {
            String word = str[i];
            if (word.length() < minlen)
                continue;
            if (!st.contains(word))
                st.put(word, 1);
            else
                st.put(word, st.get(word) + 1);
        }
        String max = " ";
        st.put(max, 0);
        for (String word : st.keys())
            if (st.get(word) > st.get(max))
            max = word;
        StdOut.println(max + " " + st.get(max));

    }
}
/*
it was the best of times it was the worst of time
it was the age of wisdom it was the age of foolishness
it was the epoch of belief it was the epoch of incredulity
it was the season of light it was the season of darkness
it was the spring of the hope it was the winter of despair
 */
